package com.wl4837;

// 环境类：支付上下文
class PaymentContext {
    private PaymentStrategy paymentStrategy;

    // 动态设置支付策略
    public void setPaymentStrategy(PaymentStrategy paymentStrategy) {
        this.paymentStrategy = paymentStrategy;
    }

    // 执行支付
    public void pay(int amount) {
        if (paymentStrategy == null) {
            throw new IllegalStateException("支付策略未设置！");
        }
        paymentStrategy.pay(amount);
    }
}